package data;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class ChordTemplate implements Serializable {
	private int[] notes;

	public ChordTemplate(int max) {
		notes = new int[max];
	}
	
	public int[] getNotes() {
		return notes;
	}
	
	public void setNotes(int[] notes) {
		this.notes = notes;
	}
	
	public void setNote(int index, int note) {
		notes[index] = note;
	}
	
	@Override
	public void serialize(OutputStream os) {
		try {
			os.write(notes.length);
			System.out.println("" + notes.length);
			for (int note: notes) {
				os.write(note);
				System.out.println("" + note);
			}
		} 
		catch (IOException ioe) {
			ioe.printStackTrace();
		}		
	}

	@Override
	public void deserialize(InputStream is) {
		try {
			notes = new int[is.read()];
			for (int i = 0; i < notes.length; i++) {
				notes[i] = is.read();
			}
		} 
		catch (IOException ioe) {
			ioe.printStackTrace();
		}		
	}
	
	@Override
	public String toString() {
		String res = "" + notes.length + " ";
		for (int i = 0; i < notes.length; i++) res += "" + notes[i] + " ";
		return res;
	}
}
